% close all
% clear all
% clc
% load matlab.mat
% 
% figure('name','Total Payoff - VaR stop-loss trading Strategy 1 & 2');
% plot(TotalPayoff2,'--gs','LineWidth',2,...
%                 'MarkerEdgeColor','k',...
%                 'MarkerFaceColor','y',...
%                 'MarkerSize',10);
% hold on
% plot(TotalPayoff1,'--ro','LineWidth',2,...
%                 'MarkerEdgeColor','k',...
%                 'MarkerFaceColor','b',...
%                 'MarkerSize',10);
% legend('return(%) - strategy 1','return(%) - strategy 2','Location','NorthWest')
% title('Total Payoff - VaR stop-loss trading Strategy 1 & 2',... 
%   'FontWeight','bold')
% xlabel('Beta estimation methods')
% ylabel('Return(%)')
% set(gca,'Xtick',1:40,'XTickLabel',{'OLS','Med','Trim','Wei','Shri','Bay','Smo','Kal','Tob','Tru','GMM'});
% 
% figure('name','Beta Estimation');
% plot(Beta_All,'--bo','LineWidth',2,...
%                 'MarkerEdgeColor','k',...
%                 'MarkerFaceColor','g',...
%                 'MarkerSize',10);
% legend('Beta','Location','NorthEast')
% title('Beta Estimation',... 
%   'FontWeight','bold')
% xlabel('Beta estimation methods')
% ylabel('Beta')
% set(gca,'Xtick',1:40,'XTickLabel',{'OLS','Med','Trim','Wei','Shri','Bay','Smo','Kal','Tob','Tru','GMM'});
%  
% figure('name','VaR Backtest - Failure Rate');
% plot(FailureRate,'--ro','LineWidth',2,...
%                 'MarkerEdgeColor','k',...
%                 'MarkerFaceColor','g',...
%                 'MarkerSize',10);
% yPos = 0.05;
% hold on
% plot(get(gca,'xlim'), [yPos yPos],'LineWidth',2); % Adapts to x limits of current axes
% legend('Failure rate(%)','Location','NorthEast')
% title('VaR Backtest - Failure Rate',... 
%   'FontWeight','bold')
% xlabel('Beta estimation methods')
% ylabel('Failure rate(%)')
% set(gca,'Xtick',1:40,'XTickLabel',{'OLS','Med','Trim','Wei','Shri','Bay','Smo','Kal','Tob','Tru','GMM'});
% 
% figure('name','VaR All')
% plot(Var_Down_All,'--go','LineWidth',2,...
%                 'MarkerEdgeColor','k',...
%                 'MarkerFaceColor','b',...
%                 'MarkerSize',10);
% legend('VaR 5(%)','Location','NorthEast')
% title('Value at Risk 5%',... 
%   'FontWeight','bold')
% xlabel('Beta estimation methods')
% ylabel('Return(%)')
% set(gca,'Xtick',1:40,'XTickLabel',{'OLS','Med','Trim','Wei','Shri','Bay','Smo', 'Kal','Tob','Tru','GMM'});
% 
% figure('name','VaR All')
% plot(Var_Up_All,'--go','LineWidth',2,...
%                 'MarkerEdgeColor','k',...
%                 'MarkerFaceColor','r',...
%                 'MarkerSize',10);
% legend('VaR 95(%)','Location','NorthEast')
% title('Value at Risk 95%',... 
%   'FontWeight','bold')
% xlabel('Beta estimation methods')
% ylabel('Return(%)')
% set(gca,'Xtick',1:40,'XTickLabel',{'OLS','Med','Trim','Wei','Shri','Bay','Smo', 'Kal','Tob','Tru','GMM'});

clear all
clc
load dtPortfolio_HOSE_20_1.mat

options = {'Smoothing','Kalman Filter'};
alpha = 0.05;
V0 = 1;

portfolio_codes = portfolio_codes_t;
porfolio_weights = porfolio_weights_t;
portfolio_date = portfolio_date_t;
Stock_Price = portfolio_close_price_t(:, 2:end);
Index_Price = portfolio_close_price_t(:, 1);
    
    
rPortfolio = getReturn(Stock_Price);
rIndex = getReturn(Index_Price);

for i=1:length(options)
    [totalPayoff1(1,i) Buy1 Sell1 totalPayoff2(1,i) Buy2 Sell2 beta VaRup VaRdown failure_rate(1,i)] ...
            = trading(Stock_Price, Index_Price, rPortfolio, rIndex, options{i},...
                       porfolio_weights, alpha, V0);
end


